{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 安装\n",
    "# !pip install python-pptx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "python-pptx 的版本： 0.6.18\n"
     ]
    }
   ],
   "source": [
    "# 查看版本\n",
    "import pptx\n",
    "print('python-pptx 的版本：', pptx.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "报告已生成，请打开PPT文件查看。\n"
     ]
    }
   ],
   "source": [
    "# 导入库\n",
    "from pptx import Presentation\n",
    "from pptx.util import Inches, Pt\n",
    "from pptx.dml.color import RGBColor\n",
    "\n",
    "# 模板下载 https://github.com/linjiwx/mp\n",
    "prs = Presentation('模板.pptx')\n",
    "\n",
    "# 添加幻灯片首页\n",
    "slide_layout0 = prs.slide_layouts[0]\n",
    "slide = prs.slides.add_slide(slide_layout0)\n",
    "\n",
    "# 设置标题和副标题文本\n",
    "title = slide.shapes.title\n",
    "subtitle = slide.placeholders[10]\n",
    "title.text = '2020年9月林骥的数据分析报告'\n",
    "subtitle.text = '2020-10-08'\n",
    "\n",
    "# 添加幻灯片，正文模块，根据实际需求选择布局版式\n",
    "\n",
    "# *************1. 主要分析结论*****************\n",
    "slide_layout1 = prs.slide_layouts[1]\n",
    "slide1 = prs.slides.add_slide(slide_layout1)\n",
    "\n",
    "# 添加标题\n",
    "title = slide1.placeholders[10]\n",
    "title.text = \"1. 主要分析结论\"\n",
    "\n",
    "# 添加正文内容\n",
    "content = slide1.placeholders[11]\n",
    "ft = content.text_frame\n",
    "ft.clear()\n",
    "p = ft.paragraphs[0]\n",
    "run = p.add_run()\n",
    "run.text = '（1) 年初制定的运动目标是平均每天走'\n",
    "\n",
    "# 重点强调的内容\n",
    "run = p.add_run()\n",
    "run.text = '10000步'\n",
    "font = run.font\n",
    "font.name = 'Arial'\n",
    "font.size = Pt(26)\n",
    "font.color.rgb = RGBColor(0, 88, 159)\n",
    "\n",
    "# 继续添加其他内容\n",
    "run = p.add_run()\n",
    "run.text = '，9月份的目标完成率为'\n",
    "\n",
    "# 重点强调的内容\n",
    "run = p.add_run()\n",
    "run.text = '108.8%'\n",
    "font = run.font\n",
    "font.name = 'Arial'\n",
    "font.size = Pt(26)\n",
    "font.color.rgb = RGBColor(0, 88, 159)\n",
    "\n",
    "# 继续添加其他内容\n",
    "run = p.add_run()\n",
    "run.text = '''，超额完成任务目标；\n",
    "\n",
    "（2) 学习的各项指标均有所提升，其中笔记方面的提升最为明显，9月底的笔记评级变成'''\n",
    "\n",
    "# 重点强调的内容\n",
    "run = p.add_run()\n",
    "run.text = 'A+'\n",
    "font = run.font\n",
    "font.name = 'Arial'\n",
    "font.size = Pt(26)\n",
    "font.color.rgb = RGBColor(0, 88, 159)\n",
    "\n",
    "# 继续添加其他内容\n",
    "run = p.add_run()\n",
    "run.text = '。'\n",
    "\n",
    "# ***************2. 目标完成情况******************\n",
    "# 添加幻灯片\n",
    "slide_layout2 = prs.slide_layouts[3]\n",
    "slide2 = prs.slides.add_slide(slide_layout2)\n",
    "# 添加正文模块标题\n",
    "title= slide2.placeholders[10]\n",
    "title.text = \"2. 目标完成情况\"\n",
    "# 插入图片 https://github.com/linjiwx/mp\n",
    "img_path='./pic/2. 目标完成情况.jpg'\n",
    "picture_placeholder = slide2.placeholders[11]\n",
    "placeholder_picture = picture_placeholder.insert_picture(img_path)\n",
    "# 添加描述内容\n",
    "content= slide2.placeholders[12]\n",
    "content.text = ' '\n",
    "\n",
    "# ***************3. 关键指标变化******************\n",
    "# 添加幻灯片\n",
    "slide_layout3 = prs.slide_layouts[6]\n",
    "slide3 = prs.slides.add_slide(slide_layout3)\n",
    "# 添加正文模块标题\n",
    "title= slide3.placeholders[10]\n",
    "title.text = \"3. 关键指标变化\"\n",
    "# 插入图片对象，主图\n",
    "img_path='./pic/3. 关键指标变化.jpg'\n",
    "picture_placeholder = slide3.placeholders[11]\n",
    "placeholder_picture = picture_placeholder.insert_picture(img_path)\n",
    "# 添加描述内容\n",
    "content= slide3.placeholders[12]\n",
    "content.text = '''与年初相比，\n",
    "各项指标均有所提升，\n",
    "其中笔记的提升最多，\n",
    "9月底的笔记评级变成A+。\n",
    "'''\n",
    "\n",
    "# ***************4. 变化原因分析******************\n",
    "# 添加幻灯片\n",
    "slide_layout4 = prs.slide_layouts[1]\n",
    "slide4 = prs.slides.add_slide(slide_layout4)\n",
    "\n",
    "# 添加正文模块标题\n",
    "title= slide4.placeholders[10]\n",
    "title.text = \"4. 变化原因分析\"\n",
    "\n",
    "# 添加描述内容\n",
    "content= slide4.placeholders[11]\n",
    "content.text = '''\n",
    "（1) 为了错开上班早高峰的时间，我早上通常在7点钟之前就到了公司，增加了很多学习和写读书笔记的时间；\n",
    "\n",
    "（2) 在OKR方法的指引下，我年初制定了精细阅读26本书和原创写作60篇文章的目标，用输出倒逼输入。\n",
    "'''\n",
    "\n",
    "# *************5. 建议改善措施*****************\n",
    "slide_layout5 = prs.slide_layouts[1]\n",
    "slide5 = prs.slides.add_slide(slide_layout5)\n",
    "\n",
    "# 添加正文模块标题\n",
    "title= slide5.placeholders[10]\n",
    "title.text = \"5. 建议改善措施\"\n",
    "\n",
    "# 添加内容\n",
    "content= slide5.placeholders[11]\n",
    "content.text = '''\n",
    "（1) 建议继续坚持运动和学习，提升自己的健康水平和能力水平，以饱满的状态投入工作，不断提高工作效率，创造出远大于回报的价值；\n",
    "\n",
    "（2) 建议加强知识分享，教会别人，比自己动手操作要难得多，但是，分享的过程会让自己收获更多，这是一件值得投入的事。\n",
    "'''\n",
    "\n",
    "# ***************6. 封底******************\n",
    "# 添加幻灯片\n",
    "slide_layout2 = prs.slide_layouts[3]\n",
    "slide2 = prs.slides.add_slide(slide_layout2)\n",
    "# 添加正文模块标题\n",
    "title= slide2.placeholders[10]\n",
    "title.text = '6. 感谢您的关注'\n",
    "# 插入图片对象，主图\n",
    "img_path='./pic/林骥.png'\n",
    "picture_placeholder = slide2.placeholders[11]\n",
    "placeholder_picture = picture_placeholder.insert_picture(img_path)\n",
    "# 添加描述内容\n",
    "content= slide2.placeholders[12]\n",
    "content.text = '用数据化解难题，让分析更加有效。'\n",
    "\n",
    "prs.save('2020年9月林骥的数据分析报告.pptx')\n",
    "\n",
    "print(\"报告已生成，请打开PPT文件查看。\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
